package com.reciver.common.manager.factory;

import java.util.TimerTask;
import com.reciver.entity.SysOperationLog;
import com.reciver.common.util.IpAddressUtil;
import com.reciver.common.component.SpringUtils;
import com.reciver.service.SysOperationLogService;
import org.springframework.jdbc.core.JdbcTemplate;

public class AsyncFactory {

    /**
     * @param log 操作日志信息
     * @return 任务task 操作日志记录
     **/
    public static TimerTask operSql(final String sql) {
        return new TimerTask(){
            @Override
            public void run() {
            	SpringUtils.getBean(JdbcTemplate.class).execute(sql);
            }
        };
    }
    /**
     * @param operLog 操作日志信息
     * @return 任务task 操作日志记录
     */
    public static TimerTask recordOper(final SysOperationLog operLog){
        return new TimerTask() {
            @Override
            public void run() {
                String address = IpAddressUtil.getCityInfo(operLog.getOperIp());
                // 远程查询操作地点
                operLog.setOperLocation(address);
                SpringUtils.getBean(SysOperationLogService.class).insertLog(operLog);;
            }
        };
    }
}